var nowDate = getDay(0);
var calendar = new lCalendar();
var starttimecalendar = new lCalendar();
var endtimecalendar = new lCalendar();
var resdata;
var url;
var trStr;
var sendData = [];
var xtsl=0;
var pdsl=0;
var cysl=0;
starttimecalendar.init({
	'trigger': '#startDate',
	'type': 'date',
	'minDate': '2021-01-01',
	'maxDate': '2099-12-31'
});
endtimecalendar.init({
	'trigger': '#endDate',
	'type': 'date',
	'minDate': '2021-01-01',
	'maxDate': '2099-12-31'
});
function ICalendarClick(){
//	onload()
}
$(document).ready(function(){
	$('#name').text(sessionStorage.getItem("name"));
	document.getElementById("startDate").value=nowDate;
	document.getElementById("endDate").value=nowDate;
	$('#searchButton').on('click',function(){
		if($('#startDate').val() > $('#endDate').val()){
			alert("开始日期不能大于结束日期")
		}else{
			getData();
		}
	});
		$.ajax({
		url: "../../typd/pandianchaxvn"
		,type:'post'
		,data:JSON.stringify({"StoreNO":"","BeginDate":document.getElementById("startDate").value,"EndDate":document.getElementById("endDate").value})
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
			console.log(res);
					xtsl=0;
					pdsl=0;
					cysl=0;
					trStr="";
					sumStr="";
					for (var i = 0; i < res.data.length; i++) {
						xtsl = xtsl+Number(res.data[i].StockQty);
						pdsl = pdsl+Number(res.data[i].CheckQty);
						cysl = cysl+Number(res.data[i].DiffQty);
					trStr   +='<tr>'
							+'<td style="color:orange" onclick = "InventorySelect(\''+res.data[i].PaperNO+'\')">'+res.data[i].StoreNO+'</td>'
							+'<td style="color:orange" onclick = "InventorySelect(\''+res.data[i].PaperNO+'\')">'+res.data[i].StoreName+'</td>'
							+'<td>'+res.data[i].PaperNO.substring(8,10)+'-'+res.data[i].PaperNO.substring(10,12)+'</td>'
							+'<td>'+res.data[i].StockQty+'</td>'
							+'<td>'+res.data[i].CheckQty+'</td>'
							+'<td>'+res.data[i].DiffQty+'</td>'
							+'</tr>'
					}
						sumStr +='<tr>'
							+'<td>'+'合计'+'</td>'
							+'<td>'+' '+'</td>'
							+'<td>'+' '+'</td>'
							+'<td>'+xtsl+'</td>'
							+'<td>'+pdsl+'</td>'
							+'<td>'+cysl+'</td>'
							+'</tr>'
			$('#shujvdiv').append(trStr);
			$('#shujvdiv').append(sumStr);
			
					$("#shujvdiv td[id]").on("click",null,function(){
						var html = $(this).html();
						var id = $(this).attr("id");
						var value = $(this).text();
						if(value != undefined){
							//tips层-上
							layer.tips(value, '#'+id, {
								tips: [1, '#0FA6D8'] //还可配置颜色
							});	
						}
					});	
		}
		,error:function(XMLHttpRequest, textStatus, errorThrown) {
		}
	});
});
function getData() {
	trStr = "";
    $("#shujvdiv").html("");
		$.ajax({
		url: "../../typd/pandianchaxvn"
		,type:'post'
		,data:JSON.stringify({"StoreNO":document.getElementById("shopcode").value,"BeginDate":document.getElementById("startDate").value,"EndDate":document.getElementById("endDate").value})
		,contentType: "application/json; charset=utf-8"
		,dataType:'json'
		,success: function(res){
					xtsl=0;
					pdsl=0;
					cysl=0;
					trStr="";
					sumStr="";
					for (var i = 0; i < res.data.length; i++) {
						xtsl = xtsl+Number(res.data[i].StockQty);
						pdsl = pdsl+Number(res.data[i].CheckQty);
						cysl = cysl+Number(res.data[i].DiffQty);
					trStr   +='<tr>'
							+'<td style="color:orange" onclick = "InventorySelect(\''+res.data[i].PaperNO+'\')">'+res.data[i].StoreNO+'</td>'
							+'<td style="color:orange" onclick = "InventorySelect(\''+res.data[i].PaperNO+'\')">'+res.data[i].StoreName+'</td>'
							+'<td>'+res.data[i].PaperNO.substring(8,10)+'-'+res.data[i].PaperNO.substring(10,12)+'</td>'
							+'<td>'+res.data[i].StockQty+'</td>'
							+'<td>'+res.data[i].CheckQty+'</td>'
							+'<td>'+res.data[i].DiffQty+'</td>'
							+'</tr>'
					}sumStr +='<tr>'
							+'<td>'+'合计'+'</td>'
							+'<td>'+' '+'</td>'
							+'<td>'+' '+'</td>'
							+'<td>'+xtsl+'</td>'
							+'<td>'+pdsl+'</td>'
							+'<td>'+cysl+'</td>'
							+'</tr>'
			$('#shujvdiv').append(trStr);
			$('#shujvdiv').append(sumStr);		
			
					$("#shujvdiv td[id]").on("click",null,function(){
						var html = $(this).html();
						var id = $(this).attr("id");
						var value = $(this).text();
						if(value != undefined){
							//tips层-上
							layer.tips(value, '#'+id, {
								tips: [1, '#0FA6D8'] //还可配置颜色
							});	
						}
					});	
		}
	});

	
}
function InventorySelect(PaperNO) {
   	url = "mdsearch?PaperNO="+PaperNO;//此处拼接内容
	window.location.href = url;
}
